import { _decorator, Component, Node, resources, Sprite, SpriteFrame } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('GameData')
export class GameData {

    /**视频时间 */
    public static videoTime:number = 0;

    /**节点 0 问题未回答， 1播放第一个，2播放第二个，3播放第三个 4播放结束*/
    public static curstep:number = 0;

    /**节点 第二个选择播放的视频 1 礼物1, 2礼物2*/
    public static step2Video:number = 0;

    /**当前问题节点*/
    public static curVideoCfg:videoCfg

    public static videoCfgs:any[] = [{"id":1,"time":33,"problem":"准备好开始了嘛","answer":"[\"是的我准备好了！\",\"稍等有内鬼\"]","right":"[0]"},{"id":2,"time":62,"problem":"对不起呜呜呜呜","answer":"[\"对不起，我是个红蛋\",\"呜呜呜呜呜呜\"]","right":"[0,1]"},{"id":4,"time":307,"problem":"前面有一个门，你准备","answer":"[\"礼貌敲一下门，然后走进去\",\"我今天非得把这个门撬开\",\"开门，你的外卖到了\"]","right":"[0,1]"},{"id":3,"time":391,"problem":"我准备好了","answer":"[\"不行，必须准备好\",\"是的，我早准备好了\"]","right":"[0]"},{"id":5,"time":446,"problem":"接受礼物","answer":"[\"被动接受\",\"必须接受\"]","right":"[0,1]"}]
   
    public static isPlaySound:boolean = false;

    public static isPlayMusic:boolean = false;

    public static tipStr:string = "";

    /**个人信息 */
    public userData:userData;

    /**拥有商店列表*/
    public static shopDataList:shopData[] = [];

    /**商店配置列表*/
    public static shopCfgs:shopCfg[] = [];

    /**日志列表*/
    public static logList:shopData[] = [];

    /**签到奖励配置表*/
    public static inviteRewardCfgList:inviteRewardCfg[] = [];

    /**轮播列表*/
    public static linkCfgs:linkCfg[] = [];

    /**ai续费价格 */
    public static aiCoin:number = 0;


    public static instance: GameData;
    constructor(){

    }
    public static getIns(){
        if (GameData.instance == null){
            GameData.instance = new GameData();
            GameData.instance.userData = new userData();
        }
        return GameData.instance
    }

     /**根据时间 获取问题数据 */
    public static getVideoConfigByTime(time:number):any{
        for (let index = 0; index < GameData.videoCfgs.length; index++) {
            let element = GameData.videoCfgs[index];
            if (element.answer && typeof element.answer  === "string"){
                element.answer  = JSON.parse(element.answer);
            }
            if (element.right && typeof element.right  === "string"){
                element.right  = JSON.parse(element.right);
            }
            if (element.time == time){
                return element;
            }
        }
        return null;
    }

    /**获取对应配置的，id 某项数据 */
    public static getItemDataByIdAndCfgs(id:number, cfgs:any[]){
        for (let index = 0; index < cfgs.length; index++) {
            let element = cfgs[index];
            if (element.id == id){
                return element;
            }
        }
        return null;
    }
}

export class userData{

    id:number;

    phone:string;

    nickname:string;

    /**简介 */
    introduce:string;

    avatar:string;

    loginIp:string;

    coin:number;

    code:string;

    inviteRewardSum: number 
    inviteRewardYesterday: number;

    onestarNum: number; 
    twostarNum: number; 
    threestarNum: number; 
    fourstarNum: number; 
    fivestarNum: number;

    inviteNum: number; 

    /**ai剩余天数 */
    leftDay: number;

    rewardStatue: number;
	uid: number;
}

/**任务配置 */
export class taskCfg{

    id:number;

    /**0 新手，1每日，成就 */
    type:number;

    /** TASK1("完成实名认证",1),
     * 
    TASK2("商场补货X次", 2),

    TASK3("分享游戏X次", 3),

    TASK4("商场接待客人X次", 4),

    TASK5("开新商场", 5),

    TASK6("升级商场", 6),

    TASK7("今日商城收益XXX金币", 7),

    TASK8("累计签到XX次", 8),

    TASK9("商场累计补货XXX次", 9),

    TASK10("商场累计接待难民X次", 10),

    TASK11("商场累计接待客人X次", 11),

    TASK12("拥有X个X星商场", 12),

    TASK13("累计邀请成功XX个用户", 13),
    
    TASK14("累计商场收益XXXX金币", 14)*/
    type2:number;

    taskType:string;

    // des:string;

    value:number;

    taskReward:number;

    /**进度值 */
    process:number;

    /**0 进行中  1 已完成 2 已领取奖励 */
    status:number;
}

/**商店配置 */
export class shopCfg{

    createBy: number; 
    createTime: number; 
    updateBy: number; 
    updateTime: number; 
    remark: number; 

    id:number;

    name:string;

    lv:number;

    lvCoin:number;

    stockCoin:number;

    openCoin:number;

    minCoin:number;

    maxCoin:number;

    num:number;

    upGradeTime: number;
    addGoodsTime: number;
}

/**商店配置 */
export class shopData{

    /**唯一ID */
    id: number;

    /**等级 */
    lv: number;

    /**0 营业中  1 待补货 2 补货中 3 升级中  4 停业中 */
    status: number;

    time:number;

    visitCount: number;
}

/**排行数据 */
export class rankData{
    userId:number;

    nickname:string;
    avatar:string;
    onestarNum:number;
    twostarNum:number;
    threestarNum:number;
    fourstarNum:number;
    fivestarNum:number;
}

/**邀请详细奖励 */
export class inviteDetialData{

    nickname:string; 

    avatar:string;

    inviteRewardSum:string;

    inviteRewardYesterday:string;
}

/**邀请人数奖励配置 */
export class inviteRewardCfg{
    id: number;
    inviteNum: number;
    rewardCoin: number;
    rewardShopId: number;
}

/**轮播配置 */
export class linkCfg{
    id: number;
    title: string;
    url: string;
    img: string;
}

/**轮播配置 */
export class videoCfg{
    //时间节点
    time: number;
    //问题
    problem:string;
    //答案
    answer: string[];
    //正确问题
    right:number[];
}


